package yaner.hotel.manager.resource.mapper.impl;

import org.springframework.stereotype.Component;
import yaner.hotel.manager.common.dto.dict.DictAddDto;
import yaner.hotel.manager.common.dto.dict.DictUpdateDto;
import yaner.hotel.manager.common.utils.SnowUtils;
import yaner.hotel.manager.common.vo.DictVo;
import yaner.hotel.manager.resource.entity.Dict;
import yaner.hotel.manager.resource.mapper.IDictMapper;

import java.util.Date;
import java.util.Objects;

@Component
public class DictMapperImpl implements IDictMapper {
    @Override
    public DictVo toVo(Dict dict) {
        Objects.requireNonNull(dict, "DictMapperImpl toVo dict is null");
        return DictVo.builder()
                .id(dict.getId())
                .dictCode(dict.getDictCode())
                .dictDesc(dict.getDictDesc())
                .categoryCode(dict.getCategoryCode())
                .categoryDesc(dict.getCategoryDesc())
                .sortNo(dict.getSortNo())
                .status(dict.getStatus())
                .build();
    }

    @Override
    public Dict toAddEntity(DictAddDto dictAddDto) {
        Objects.requireNonNull(dictAddDto, "DictMapperImpl toAddEntity dictAddDto is null");
        return Dict.builder()
                .id(SnowUtils.nextId())
                .dictCode(dictAddDto.getDictCode())
                .dictDesc(dictAddDto.getDictDesc())
                .categoryCode(dictAddDto.getCategoryCode())
                .categoryDesc(dictAddDto.getCategoryDesc())
                .sortNo(dictAddDto.getSortNo())
                .status(dictAddDto.getStatus())
                .createTime(new Date())
                .updateTime(new Date())
                .build();
    }

    @Override
    public Dict toUpdateEntity(DictUpdateDto dictUpdateDto) {
        Objects.requireNonNull(dictUpdateDto, "DictMapperImpl toUpdateEntity dictUpdateDto is null");
        return Dict.builder()
                .id(dictUpdateDto.getId())
                .dictCode(dictUpdateDto.getDictCode())
                .dictDesc(dictUpdateDto.getDictDesc())
                .categoryCode(dictUpdateDto.getCategoryCode())
                .categoryDesc(dictUpdateDto.getCategoryDesc())
                .sortNo(dictUpdateDto.getSortNo())
                .status(dictUpdateDto.getStatus())
                .updateTime(new Date())
                .build();
    }
}
